import store from '@/store'

export default {
	inserted(el, binding, vnode) {
		const {value} = binding
		const roles = store.getters && store.getters.roles

		if (value && value instanceof Array && value.length > 0) {
			const permissions = value

			let hasPermission = false

			hasPermission = permissions.some(perm => {
				return perm == roles
			})

			if (!hasPermission) {
				el.parentNode && el.parentNode.removeChild(el)
			}
		} else {
			throw new Error(`need perms! Like v-permission="['GET /aaa','POST /bbb']"`)
		}
	}
}
